﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Ordinaire.Commerce
{
    /// <summary>
    /// This is a concrete Pay class that represents cash payment (notes and coins).
    /// </summary>
    public class CashPay : Pay
    {
        /// <summary>
        /// Holds the list of cash denominations used to pay.
        /// </summary>
        public Dictionary<float, ushort> Denominations { get; set; }

        /// <summary>
        /// Holds the payment amount value.
        /// </summary>
        /// <remarks>Stored denominations will be reset when amount is set</remarks>
        public override decimal Amount
        {
            get
            {
                // calculates amount from denominations
                if (Denominations != null && Denominations.Count > 0)
                {
                    decimal amount = 0;
                    foreach (var item in Denominations)
                    {
                        amount += (decimal) item.Key * item.Value;
                    }
                    return amount;
                }

                return base.Amount;
            }
            set
            {
                base.Amount = value;

                // reset denomination when value is set.
                Denominations = null;
            }
        }
    }
}
